﻿Imports System
Imports System.IO
Imports System.Runtime.Serialization
Imports System.Runtime.Serialization.Formatters.Binary

<Serializable()> Public Class AermodProject
    Private m_AermodVersion As String = "2300" '保存的文件版本控制标志。当需要修改保存的文件的结构时，提示以前版本的软件打开项目更新软件
    Private m_Aermod As New Aermod
    Private m_Aermap As New Aermap
    Private m_IsSaved As Boolean = False '保存标志
    Private m_SaveName As String
    Private m_Iscal As Boolean '重新计算过的标志
    Private m_Aermet As New Met.Aermet
    Private m_ProjSetCollection As New ProjSetCollection '方案的集合

    ''' <summary>
    ''' 只保存文件名
    ''' </summary>
    ''' <remarks></remarks>
    Private m_DemFileFor3D As String
    ''' <summary>
    ''' 只保存文件名
    ''' </summary>
    ''' <remarks></remarks>
    Private m_TifFileForGid As String
    ''' <summary>
    ''' AermodSystem的版本标志
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Property AermodVersion() As String
        Get
            Return Me.m_AermodVersion
        End Get
        Set(ByVal value As String)
            Me.m_AermodVersion = value
        End Set
    End Property

    Property Aermod() As Aermod
        Get
            Return Me.m_Aermod
        End Get
        Set(ByVal value As Aermod)
            Me.m_Aermod = value
        End Set
    End Property
    
    Property Aermap() As Aermap
        Get
            Return Me.m_Aermap
        End Get
        Set(ByVal value As Aermap)
            Me.m_Aermap = value
        End Set
    End Property
    ''' <summary>
    ''' 保存标志
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Property IsSaved() As Boolean
        Get
            Return Me.m_IsSaved
        End Get
        Set(ByVal value As Boolean)
            Me.m_IsSaved = value
        End Set
    End Property
    ''' <summary>
    ''' 保存文件的名称
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Property SaveName() As String
        Get
            Return Me.m_SaveName
        End Get
        Set(ByVal value As String)
            Me.m_SaveName = value
        End Set
    End Property
    ''' <summary>
    ''' 如果用户修改了程序，就需要重新进行计算。
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Property Iscal() As Boolean
        Get
            Return m_Iscal
        End Get
        Set(ByVal value As Boolean)
            m_Iscal = value
        End Set
    End Property

    ''' <summary>
    ''' Aermet对象
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Property Aermet() As Met.Aermet
        Get
            Return m_Aermet
        End Get
        Set(ByVal value As Met.Aermet)
            m_Aermet = value
        End Set
    End Property

    ''' <summary>
    ''' 方案对象的集合
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Property ProjSetCollection() As ProjSetCollection
        Get
            Return Me.m_ProjSetCollection
        End Get
        Set(ByVal value As ProjSetCollection)
            Me.m_ProjSetCollection = value
        End Set
    End Property
    ''' <summary>
    ''' 只保存文件名
    ''' </summary>
    ''' <remarks></remarks>
    Property DemFileFor3D() As String
        Get
            Return Me.m_DemFileFor3D
        End Get
        Set(ByVal value As String)
            Me.m_DemFileFor3D = value
        End Set
    End Property
    ''' <summary>
    ''' 只保存文件名
    ''' </summary>
    ''' <remarks></remarks>
    Property TifFileForGid() As String
        Get
            Return Me.m_TifFileForGid
        End Get
        Set(ByVal value As String)
            Me.m_TifFileForGid = value
        End Set
    End Property
    ''' <summary>
    ''' 获取项目对应的文件夹的路径，不包含“\”
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetProjectPath() As String
        Dim strNameLast As String = CAermod.GetFileName(Me.m_SaveName) '获取没有扩展名的文件
        '如果该文件所在目录没有相应的文件夹，则创建一个主文件夹
        Dim Path As String = My.Computer.FileSystem.GetFileInfo(Me.m_SaveName).DirectoryName
        Dim dirName As String = ""
        dirName = Path & "\" & strNameLast
        Return dirName
    End Function

    ''' <summary>
    ''' 反回与地形相对应的网格的左下角的UTM坐标
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetLeftButtomUtmXY() As Point3D
        Dim LBUtm As New Point3D
        LBUtm.x = Me.m_Aermap.Control.AnchorXY.Xautm - (Me.m_Aermap.Control.AnchorXY.Xauser - Me.m_Aermod.Receptor.SubGridCart(0).Xinit)
        LBUtm.y = Me.m_Aermap.Control.AnchorXY.Yautm - (Me.m_Aermap.Control.AnchorXY.Yauser - Me.m_Aermod.Receptor.SubGridCart(0).Yinit)
        Return LBUtm
    End Function
    ''' <summary>
    ''' 返回X坐标方向上，相对坐标与UTM坐标之间的偏移量
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetOffsetX() As Double
        Return Me.m_Aermap.Control.AnchorXY.Xautm - Me.m_Aermap.Control.AnchorXY.Xauser
    End Function
   
    ''' <summary>
    ''' 返回Y坐标方向上，相对坐标与UTM坐标之间的偏移量
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetOffsetY() As Double
        Return Me.m_Aermap.Control.AnchorXY.Yautm - Me.m_Aermap.Control.AnchorXY.Yauser
    End Function
    <OnDeserializing()> _
    Friend Sub OnDeserializingMethod(ByVal context As StreamingContext)
    End Sub

    <OnDeserialized()> _
    Friend Sub OnDeserializedMethod(ByVal context As StreamingContext)
        If Me.m_Aermet Is Nothing Then
            Me.m_Aermet = New Met.Aermet
            Me.m_Aermod.MetSource.SelectedMetFile = True
            Me.m_Aermet.Run = False
            Me.m_Aermap.Run = True
        End If

    End Sub


End Class
